package com.blb.demo1;

/**
 * 单例模式
 * 懒汉式
 */
public class SingletonPattern2 {

    private static volatile SingletonPattern2 singletonPattern=null;
    private SingletonPattern2() {
    }
    public static synchronized SingletonPattern2 getBean(){
        //双检索
        if (singletonPattern==null){
            synchronized (SingletonPattern2.class) {
                if (singletonPattern == null) {
                    singletonPattern = new SingletonPattern2();
                }
            }
        }
        return singletonPattern;
    }
}
